<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/4/13
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    <script type=“text/javascript” src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
    <script type=“text/javascript” src="${pageContext.request.contextPath}/js/json2.js"></script>
</head>
<body>

<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder">考勤管理</strong></div>
        <div class="form-group">
            <div class="label">
                <label>日期查询</label>
            </div>
            <div class="field">
                <input type="date" class="input w50" value="" id="selectdate" onchange="selectDate()" />
<%--                <input type="button" value="查询" onclick="selectDate()">--%>
                <button type="button" class="button border-blue" id="excell" onclick="method5('dataTable1')">导出考勤表格</button>
                <div class="tips"></div>
            </div>
        </div>
        <table class="table table-hover text-center" id="dataTable1">
            <tr>
                <th width="120">编号</th>
                <th>用户名</th>
                <th>出勤日期</th>
                <th>上班时间</th>
                <th>下班时间</th>
                <th>是否迟到</th>
                <th>是否早退</th>
                <th>操作</th>
            </tr>
            <div id="content1">
            <c:forEach items="${dateList}" var="dateList" varStatus="a">
                <tr>
                    <td> ${a.count}</td>
                    <td>${dateList.user.userName}</td>
                    <td><fmt:formatDate value="${dateList.brushDate}" dateStyle="medium" pattern="yyyy-MM-dd" /></td>
                    <td> <fmt:formatDate value="${dateList.attendanceTime.mintime}" dateStyle="medium" pattern="HH:mm:ss" var="mintime" />${mintime}</td>
                    <td> <fmt:formatDate value="${dateList.attendanceTime.maxtime}" dateStyle="medium" pattern="HH:mm:ss" var="maxtime" />${maxtime}</td>
                    <td>
                        <c:if test="${mintime>'08:00:00'}">
                            <a class="button border-red" href="javascript:void(0)"
                              >迟到</a>
                        </c:if>
                    </td>
                    <td>
                        <c:if test="${maxtime<'18:00:00'}">
                            <a class="button border-red" href="javascript:void(0)"
                             >早退</a>
                        </c:if>
                    </td>
                    <td>
                        <div class="button-group"><a class="button border-blue" href="javascript:void(0)"
                                                     onclick="return updateUser(${userlist.userId})"><span
                                class="icon-trash-o"></span> 查看详情</a>
                        </div>
                    </td>
                </tr>
            </c:forEach>
            </div>
            <tr>
                <td colspan="8">
                    <div class="pagelist">
                        共${userlist.totalPageNumber}页
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=1">首页</a>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.prePageNumber}">上一页</a>
                        <c:forEach var="bianhaoelement" begin="1" end="${userlist.totalPageNumber}" step="1">
                      <c:if test="${bianhaoelement >= userlist.prePageNumber && bianhaoelement <= userlist.nextPageNumber}">
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${bianhaoelement}">${bianhaoelement}</a>
                      </c:if>
                        </c:forEach>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.nextPageNumber}">下一页</a>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.totalPageNumber}">尾页</a>
                </td>
            </tr>
        </table>
    </div>
</form>


<script>
    //打印表格
    var idTmr;

    function getExplorer() {
        var explorer = window.navigator.userAgent;
        //ie
        if(explorer.indexOf("MSIE") >= 0) {
            return 'ie';
        }
        //firefox
        else if(explorer.indexOf("Firefox") >= 0) {
            return 'Firefox';
        }
        //Chrome
        else if(explorer.indexOf("Chrome") >= 0) {
            return 'Chrome';
        }
        //Opera
        else if(explorer.indexOf("Opera") >= 0) {
            return 'Opera';
        }
        //Safari
        else if(explorer.indexOf("Safari") >= 0) {
            return 'Safari';
        }
    }

    function method5(tableid) {
        if(getExplorer() == 'ie') {
            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            var oWB = oXL.Workbooks.Add();
            var xlsheet = oWB.Worksheets(1);
            var sel = document.body.createTextRange();
            sel.moveToElementText(curTbl);
            sel.select();
            sel.execCommand("Copy");
            xlsheet.Paste();
            oXL.Visible = true;

            try {
                var fname = oXL.Application.GetSaveAsFilename("Excel.xls",
                    "Excel Spreadsheets (*.xls), *.xls");
            } catch(e) {
                print("Nested catch caught " + e);
            } finally {
                oWB.SaveAs(fname);
                oWB.Close(savechanges = false);
                oXL.Quit();
                oXL = null;
                idTmr = window.setInterval("Cleanup();", 1);
            }

        } else {
            tableToExcel(tableid)
        }
    }

    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html><head><meta charset="UTF-8"></head><body><table  border="1">{table}</table></body></html>',
            base64 = function(
                s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            },
            format = function(s, c) {
                return s.replace(/{(\w+)}/g, function(m, p) {
                    return c[p];
                })
            }
        return function(table, name) {
            if(!table.nodeType)
                table = document.getElementById(table)
            var ctx = {
                worksheet: name || 'Worksheet',
                table: table.innerHTML
            }
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
</script>

<script type="text/javascript">

    function selectDate(){
        var selectdate=$("#selectdate").val();
        console.log(selectdate);
        window.location.href="${pageContext.request.contextPath}/attendancPage.do?date=" + selectdate;
    }
    function selectDate1(){
        var selectdate=$("#selectdate").val();
        console.log(selectdate);
        $.ajax({
            data:"date=" + selectdate,
            type: "post",
            dataType: 'json',
            url:"attendancPagebyDay.do",
            success:function (data){
                var list = data;
                console.log(list)
                for (var i=0;i<list.length;i++){
                    var userName= list[i].user.userName;
                    var brushDate =ConvertJSONDateToJSDateObject(list[i].brushDate);
                    var mintime = list[i].attendanceTime.mintime;
                    var maxtime = list[i].attendanceTime.maxtime;
                    console.log(userName+"--"+brushDate+"--"+mintime+"--"+maxtime);
                }
                $("#content1").append()

            },
            error: function (data) {
                alert("fail");
            }
        })
    }
    function updateStatus(userId, userStatus) {
        $.ajax({
            data: "userId=" + userId + "&userStatus=" + userStatus,
            type: "POST",
            dataType: 'json',
            url: "updateUserStatus.do",
            success: function (data) {
                location.reload();
                var input = document.getElementById(data.userId);
                if (data.userStatus == 'Y') {
                    input.setAttribute("value", "禁用");
                } else {
                    input.setAttribute("value", "启用");
                }
            },

            error: function (data) {
                alert("fail");
            }
        });
    }

    function updateUser(id) {
        if (confirm("您确定要修改" + id + "吗?")) {
            console.log(id);
            window.location.href = "${pageContext.request.contextPath}/updateUserPage.do?id=" + id;
        }
    }

    function del(id) {
        if (confirm("您确定要删除吗?")) {
            window.location.href = "${pageContext.request.contextPath}/deleteUser.do?id=" + id;
        }
    }

    $("#checkall").click(function () {
        $("input[name='id[]']").each(function () {
            if (this.checked) {
                this.checked = false;
            } else {
                this.checked = true;
            }
        });
    })

    function DelSelect() {
        var Checkbox = false;
        $("input[name='id[]']").each(function () {
            if (this.checked == true) {
                Checkbox = true;
            }
        });
        if (Checkbox) {
            var t = confirm("您确认要删除选中的内容吗？");
            if (t == false) return false;
        } else {
            alert("请选择您要删除的内容!");
            return false;
        }
    }

</script>
</body>
</html>